/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLELF_HEADER32_H
#define PLELF_HEADER32_H

#include <elf/plelfstddef.h>
#include <elf/plelfheaderenums.h>
#include <elf/plelfidentification.h>

namespace PLSDK {

#define EI_IDENT 16

/**
 * The elf header information.
 */
class PLELFHeader32 : public PLELFHeaderEnums {
public:
	/**
	 * Constructor.
	 */
	PLELFHeader32() {}
	/**
	 * The initial bytes mark the file as an object file and provide machine-independent data
	 * with which to decode and interpret the file’s contents.
	 */
	unsigned char	e_ident[EI_IDENT];
	/**
	 * This member identifies the object file type.
	 */
	Elf32_Half		e_type;
	/**
	 * This member’s value specifies the required architecture for an individual file.
	 */
	Elf32_Half		e_machine;
	/**
	 * This member identifies the object file version.
	 * 
	 */
	Elf32_Word		e_version;
	/**
	 * This member gives the virtual address to which the system first transfers control, thus
	 * starting the process. If the file has no associated entry point, this member holds zero.
	 */
	Elf32_Addr		e_entry;
	/**
	 * This member holds the program header table’s file offset in bytes. If the file has no
	 * program header table, this member holds zero.
	 */
	Elf32_Off		e_phoff;
	/**
	 * This member holds the section header table’s file offset in bytes. If the file has no
	 * section header table, this member holds zero.
	 */
	Elf32_Off		e_shoff;
	/**
	 * This member holds processor-specific flags associated with the file.
	 */
	Elf32_Word		e_flags;
	/**
	 * This member holds the ELF header's size in bytes.
	 */
	Elf32_Half		e_ehsize;
	/**
	 * This member holds the size in bytes of one entry in the file's program header table;
	 * all entries are the same size.
	 */
	Elf32_Half		e_phentsize;
	/**
	 * This member holds the number of entries in the program header table.
	 */
	Elf32_Half		e_phnum;
	/**
	 * This member holds a section header's size in bytes.
	 * A section header is one entry in the section header table; all entries are the same size.
	 */
	Elf32_Half		e_shentsize;
	/**
	 * This member holds the number of entries in the section header table.
	 * Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes.
	 * If a file has no section header table, e_shnum holds the value zero.
	 */
	Elf32_Half		e_shnum;
	/**
	 * This member holds the section header table index of the entry associated with the section name string table.
	 */
	Elf32_Half		e_shstrndx;
	/**
	 * Get the type of the elf file from the header.
	 *
	 * @return The type of the elf file.
	 */
	inline PLELFHeader32::EType type();
	/**
	 * Get the machine of the elf header.
	 *
	 * @return The machine.
	 */
	inline PLELFHeader32::EMachine machine();
	/**
	 * Get the version of the elf file format.
	 *
	 * @return The version.
	 */
	inline PLELFHeader32::EVersion version();
	/**
	 * Get the identification part of the header.
	 *
	 * @return The identification.
	 */
	inline PLElfIdentification *identification();
} __attribute__((packed));

PLELFHeader32::EType PLELFHeader32::type() {
	return (PLELFHeader32::EType)e_type;
}

PLELFHeader32::EMachine PLELFHeader32::machine() {
	return (PLELFHeader32::EMachine)e_machine;
}

PLELFHeader32::EVersion PLELFHeader32::version() {
	return (PLELFHeader32::EVersion)e_version;
}

PLElfIdentification *PLELFHeader32::identification() {
	return reinterpret_cast<PLElfIdentification *>(e_ident);
}

}

#endif
